<?php
/*
 * Copyright 2009 Eat Local Food, LLC
 * Copyright (c) 2007 osCommerce (this file was written after
 * code review of osCommerce).
 *
 * This file is part of gwtCommerce.
 *
 * gwtCommerce is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * gwtCommerce is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with gwtCommerce.  If not, see <http://www.gnu.org/licenses/>.
 */

define('IN_ADMIN_COMPONENT_CONTROLLER', 'true');

class ConfigurationGroupComponent
{
	function ConfigurationGroupComponent()
	{
	}

	function action(&$params, $action='query')
	{
		return $this->query($params);
	}

	function query(&$params)
	{		
		$handle = get_class($this);
		$groupId = (int)$params['configuration_group_id'];

		$sqlQuery = 'select cg.configuration_group_id, cg.configuration_group_title, cg.configuration_group_description ' .
		'from ' . TABLE_CONFIGURATION_GROUP . ' cg, ' . TABLE_CONFIGURATION . ' c ' .
		'where visible = 1 and cg.configuration_group_id = c.configuration_group_id ' .
		'group by cg.configuration_group_id ' .
		'order by cg.sort_order';
		$dataReturned = mysql_query($sqlQuery) or die(mysql_error());
		$i = 0;
		while($row = mysql_fetch_array($dataReturned))
		{
			$id = (int)$row['configuration_group_id'];
			$value{$handle}{$i}{'id'}= $id;
			$value{$handle}{$i}{'title'}= $row['configuration_group_title'];
			$value{$handle}{$i}{'description'}= $row['configuration_group_description'];

			// Make sure that ConfigurationComponent has a value
			if ($groupId == 0) {
				$params['configuration_group_id'] = $id;
				$groupId = $id;
			}

			$i++;
		}

		return $value;
	}
}
?>
